var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    }; Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AudioManager"),
    r = e("ModuleUI"),
    s = e("Game"),
    l = e("AD"),
    _ = cc._decorator,
    c = _.ccclass,
    d = _.property,
    h = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.level_num_label = null),
                (t.exp_bar_mask = null),
                (t.exp_num_label = null),
                (t.free_exp_node = null),
                (t.video_exp_node = null),
                (t.box_node = null),
                (t.left_btn_list = []),
                (t.right_view_list = []),
                (t.task_red_dot_node = null),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this);
                var t = n.GlobalParams.PlayerInfo.value;
                this.level_num_label.string = "Lv" + t.level;
                var o = t.exp,
                    a = Math.floor(t.level / 10);
                a = a > 6 ? 6 : a;
                var i = s.default.season_exp[a];
                (this.exp_num_label.string = o + "/" + i),
                    (this.exp_bar_mask.width = (264 * o) / i),
                    t.level > 70
                        ? ((this.free_exp_node.active = !1),
                            (this.video_exp_node.active = !1),
                            (this.box_node.active = !0),
                            (this.box_node.children[1].getComponent(cc.Label).string = "x " + (70 - t.house_box)))
                        : ((this.free_exp_node.active =
                            n.GlobalParams.PlayerSeasonInfo.value.today_exp != new Date().toLocaleDateString()),
                            (this.video_exp_node.active = !this.free_exp_node.active),
                            (this.box_node.active = !1)),
                    this.showRightView(0),
                    this.showTaskDotInfo();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_UPDATE_ADD_PLAYER_LEVEL_EXP, this.addExpInfo, this);
            }),
            (t.prototype.showTaskDotInfo = function () {
                this.task_red_dot_node.active = !1;
                for (var e = n.GlobalParams.PlayerTaskInfo.value, t = 0; t < s.default.task_info.length; t++) {
                    var o = e.schedule[t],
                        a = s.default.task_info[t].schedule;
                    if (((this.task_red_dot_node.active = -1 != o && o >= a), this.task_red_dot_node.active)) break;
                }
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                e.prototype.OnClick.call(this, t);
                var a = t.node.name;
                switch (a) {
                    case "back_btn":
                        this.closeThisPopup();
                        break;
                    case "get_exp":
                    case "video_get_exp":
                        var r = function () {
                            o.addExpInfo("", 500);
                            var e = n.GlobalParams.PlayerSeasonInfo.value;
                            e.today_exp != new Date().toLocaleDateString() &&
                                ((e.today_exp = new Date().toLocaleDateString()),
                                    (n.GlobalParams.PlayerSeasonInfo.value = e),
                                    (o.free_exp_node.active = !1),
                                    (o.video_exp_node.active = !0));
                        };
                        "video_get_exp" == a
                            ? l.default.getInstance().showVideo(function (e) {
                                i.default.playGameBGM(), e == l.ResultEnum.Success && r();
                            })
                            : r();
                        break;
                    case "award_btn":
                        this.showRightView(0);
                        break;
                    case "task_btn":
                        (this.task_red_dot_node.active = !1), this.showRightView(1);
                        break;
                    case "box_btn":
                        var s = n.GlobalParams.PlayerInfo.value;
                        70 - s.house_box > 0 &&
                            (this.uiManager.addZsNum(100), (s.house_box += 1), (n.GlobalParams.PlayerInfo.value = s));
                }
            }),
            (t.prototype.showRightView = function (e) {
                for (var t = 0; t < 2; t++)
                    (this.left_btn_list[t].children[0].active = t == e), (this.right_view_list[t].active = t == e);
            }),
            (t.prototype.addExpInfo = function (e, t) {
                var o = this,
                    i = t,
                    r = n.GlobalParams.PlayerInfo.value,
                    l = r.exp,
                    _ = Math.floor(r.level / 10);
                _ = _ > 6 ? 6 : _;
                var c = s.default.season_exp[_],
                    d = l + i > c ? l + i - c : 0;
                if (0 == d)
                    cc.tween(this.exp_bar_mask)
                        .to(0.5, { width: (264 * (l + i)) / c })
                        .call(function () {
                            (r.exp += i),
                                r.exp == c &&
                                ((o.exp_bar_mask.width = 0),
                                    (r.exp = 0),
                                    (r.level += 1),
                                    (o.level_num_label.string = "Lv" + r.level)),
                                (_ = (_ = Math.floor(r.level / 10)) > 6 ? 6 : _),
                                (o.exp_num_label.string = r.exp + "/" + s.default.season_exp[_]),
                                (n.GlobalParams.PlayerInfo.value = r),
                                o.emitEvent(a.default.SEND_UPDATE_PLAYER_SEASON_LEVEL_INFO);
                        })
                        .start();
                else {
                    var h = 264 - this.exp_bar_mask.width;
                    _ = (_ = Math.floor((r.level + 1) / 10)) > 6 ? 6 : _;
                    var u = (264 * d) / s.default.season_exp[_];
                    cc.tween(this.exp_bar_mask)
                        .to(h / 264, { width: 264 })
                        .call(function () {
                            (o.exp_bar_mask.width = 0),
                                (r.level += 1),
                                (o.level_num_label.string = "Lv" + r.level),
                                (_ = (_ = Math.floor(r.level / 10)) > 6 ? 6 : _);
                            var e = s.default.season_exp[_];
                            (o.exp_num_label.string = "0/" + e),
                                d > e
                                    ? ((d -= e),
                                        (u -= 264),
                                        cc
                                            .tween(o.exp_bar_mask)
                                            .to(1, { width: 264 })
                                            .call(function () {
                                                (o.exp_bar_mask.width = 0),
                                                    (r.level += 1),
                                                    (o.level_num_label.string = "Lv" + r.level),
                                                    (_ = (_ = Math.floor(r.level / 10)) > 6 ? 6 : _),
                                                    (o.exp_num_label.string = "0/" + s.default.season_exp[_]);
                                            })
                                            .to(u / 264, { width: u })
                                            .call(function () {
                                                (r.exp = d),
                                                    (_ = (_ = Math.floor(r.level / 10)) > 6 ? 6 : _),
                                                    (o.exp_num_label.string = r.exp + "/" + s.default.season_exp[_]),
                                                    (n.GlobalParams.PlayerInfo.value = r),
                                                    o.emitEvent(a.default.SEND_UPDATE_PLAYER_SEASON_LEVEL_INFO);
                                            })
                                            .start())
                                    : cc
                                        .tween(o.exp_bar_mask)
                                        .to(u / 264, { width: u })
                                        .call(function () {
                                            (r.exp = d),
                                                (_ = (_ = Math.floor(r.level / 10)) > 6 ? 6 : _),
                                                (o.exp_num_label.string = r.exp + "/" + s.default.season_exp[_]),
                                                (n.GlobalParams.PlayerInfo.value = r),
                                                o.emitEvent(a.default.SEND_UPDATE_PLAYER_SEASON_LEVEL_INFO);
                                        })
                                        .start();
                        })
                        .start();
                }
            }),
            oo([d(cc.Label)], t.prototype, "level_num_label", void 0),
            oo([d(cc.Node)], t.prototype, "exp_bar_mask", void 0),
            oo([d(cc.Label)], t.prototype, "exp_num_label", void 0),
            oo([d(cc.Node)], t.prototype, "free_exp_node", void 0),
            oo([d(cc.Node)], t.prototype, "video_exp_node", void 0),
            oo([d(cc.Node)], t.prototype, "box_node", void 0),
            oo([d(cc.Node)], t.prototype, "left_btn_list", void 0),
            oo([d(cc.Node)], t.prototype, "right_view_list", void 0),
            oo([d(cc.Node)], t.prototype, "task_red_dot_node", void 0),
            oo([c], t)
        );
    })(r.default);
o.default = h;
